﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Models;
using System.Data;

public partial class Admin_User_wxUserList : AdminBase
{
    private DataTable dc = new DataTable();
    public static bool EditUser = false;
    protected void Page_Load(object sender, EventArgs e)
    {
       
        if (!Page.IsPostBack)
        {
                grdbind();
        }
            
    }


    public void grdbind()
    {
        using (Entities bll = new Entities())
        {

            var Bpl = from u in bll.User.OrderBy(u => u.UID) select u;
            if (txtUtel.Text.Trim() != "")
            {
                Bpl = Bpl.Where(p => p.UTel.Contains(txtUtel.Text.Trim()) || p.UNickName.Contains(txtUtel.Text.Trim()) || p.UTrueName.Contains(txtUtel.Text.Trim()));
            }

            //PagedDataSource pds = new PagedDataSource();
            //pds.DataSource= Bpl.ToList();
            //pds.AllowPaging = true;
            AspNetPager1.RecordCount = Bpl.Count(); //记录总数；
            //pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex;
            //pds.PageSize = AspNetPager1.PageSize;
            this.rptList.DataSource = Bpl.Skip((AspNetPager1.CurrentPageIndex-1) * AspNetPager1.PageSize).Take(AspNetPager1.PageSize).ToList();  //这里好像一定要Tolist();不然会有点错误；;
            this.rptList.DataBind();
        }
    }


    protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
    {   //当页面页数改变时，执行这个方法；
        AspNetPager1.CurrentPageIndex = e.NewPageIndex;
        grdbind();
    }
    protected void rptList_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        string _SOpenId = e.CommandArgument.ToString();
        Entities bll = new Entities();
        User model = bll.User.First(p => p.UOpenID == _SOpenId);

        switch (e.CommandName.ToLower())
        {
            //case "ibtnlock":
            //    if (model.STATE == 0)
            //        model.STATE = 1;
            //    else
            //        model.STATE = 0;
            //    break;
            case "ibtshangjia":
                if (model.Ustate == 0)
                {
                    model.Ustate = 1;
                    EditUser = true;
                }
                else
                    model.Ustate = 0;
                break;
            case "del":
                bll.User.Remove(model);
                bll.SaveChanges();
                break;

        }

        bll.SaveChanges();
        Response.Redirect("wxUserList.aspx");
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        grdbind();
    }
}